package com.econ.powercloud.ems.timing.report.strategy;

import com.econ.powercloud.clickhouse.entity.EmsStatisticalMonth;
import com.econ.powercloud.ems.dal.entity.EmsDevice;
import com.econ.powercloud.ems.pojo.EmsPriceInfoVO;
import com.econ.powercloud.ems.pojo.InComeCalculationVO;
import com.econ.powercloud.ems.pojo.MeterHisDataVO;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author : zjf
 * @Description : 计算尖峰平谷收益策略模式入口
 * @Date : 2022/3/26 10:43
 * @Modified by : zjf
 */
@Component
public class IncomeCalculationStrategy {

    @Autowired
    private List<AbstractIncomeCalculationProcess> calculationProcessList;

    private Map<Integer, AbstractIncomeCalculationProcess> processMap = Maps.newHashMap();

    @PostConstruct
    private void init() {
        processMap = calculationProcessList.stream().collect(Collectors.toMap(AbstractIncomeCalculationProcess::getIncomeModelId, item -> item));
    }

    public InComeCalculationVO calculation(Integer incomeModelId, MeterHisDataVO meterHisDataVO,
                                           Map<String, EmsStatisticalMonth> timeEpMap,
                                           EmsDevice emsDevice, EmsPriceInfoVO emsPriceInfoVO,
                                           Long startDayTime){
        AbstractIncomeCalculationProcess process = processMap.get(incomeModelId);
        if (process == null) {
            return null;
        }
        InComeCalculationVO calculationVO= process.calculation(meterHisDataVO,timeEpMap,emsDevice,emsPriceInfoVO,startDayTime);
        return calculationVO;
    }

}
